{extend name="common/base" /}

{block name="style"}
<style>
    .img-bg{
        background-size: 100% 100%;
        background-repeat: no-repeat;
    }
</style>
{/block}
{block name="toindex"}
{/block}
{block name="body"}
<div class="smrz-mains">
    <div class="smrz-top">根据平台规定，需要完成实名认证，认证成功后，赠
        送10元优惠券</div>
    <form method="post" id="auth-form" enctype="multipart/form-data" action=""> 
        <div class="smrz-boys">
            <ul class="smrz-nav">
                <li>
                    <div class="smrz-nav-z">真实姓名</div>
                    <input type="text" name="real_name" class="smrz-input js-real-name form-data" value="{$user_info.real_name}">
                </li>
                <li>
                    <div class="smrz-nav-z">身份证号</div>
                    <input type="text" name="identity_number" class="smrz-input js-identity-number form-data" value="{$user_info.identity_number}">
                </li>            
            </ul>
            <ul class="smrz-nav2">
                <li>
                    <p class="smrz-nav2-ps">+</p>
                    <p class="smrz-nav2-ps">身份证正面照</p>
                    <input type="hidden" name="identity_img_list0" class="identity_img_list0 form-data" value="{present name="$user_info['identity_img_list'][0]"}
                           {$user_info['identity_img_list'][0]}
                           {/present}">
                           <input type="file" class="nav-file" id="identity_img_list0">
                </li>
                <li>
                    <p class="smrz-nav2-ps">+</p>
                    <p class="smrz-nav2-ps">身份证反面照</p>
                    <input type="hidden" name="identity_img_list1" class="identity_img_list1 form-data" value="{present name="$user_info['identity_img_list'][1]"}
                           {$user_info['identity_img_list'][1]}
                           {/present}">
                           <input type="file" class="nav-file" id="identity_img_list1">
                </li> 
                <li>
                    <p class="smrz-nav2-ps">+</p>
                    <p class="smrz-nav2-ps">手持身份证照</p>
                    <input type="hidden" name="identity_img_list2" class="identity_img_list2 form-data" value="{present name="$user_info['identity_img_list'][2]"}
                           {$user_info['identity_img_list'][2]}
                           {/present}">
                           <input type="file" class="nav-file" id="identity_img_list2">
                </li>  
            </ul>
        </div>
        <div class="smrz-buttom">
            <!--  class加上smrz-but-tj2为蓝色背景按钮 -->
            <div class="smrz-but-tj">提交审核</div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script>

    function isSubmit() {
        var num = 0;
        var d = $(".form-data");
        $.each(d, function (index, domEle) {
            if ($(domEle).val() !== '') {
                num++;
            }
        });

        if (num >= 5) {
            $('.smrz-but-tj').addClass('smrz-but-tj2');
        }
    }

    $(".form-data").blur(function () {
        isSubmit();
    });

    $("#identity_img_list0").change(function () {
        readURL(this, 'identity_img_list0');

    });

    $("#identity_img_list1").change(function () {
        readURL(this, 'identity_img_list1');
    });

    $("#identity_img_list2").change(function () {
        readURL(this, 'identity_img_list2');
    });

     mui('body').on('tap', '.smrz-but-tj2', function () {
        var flag = 1;
        var err = '';

        if (!$(".js-real-name").val()) {
            err = '请填写真实姓名';
            flag = 0;
        }
        if (!$(".js-identity-number").val()) {
            err = '请填写身份证号';
            flag = 0;
        }
        if (!$(".identity_img_list0").val()) {
            err = '请上传身份证正面照';
            flag = 0;
        }
        if (!$(".identity_img_list1").val()) {
            err = '请上传身份证正面照';
            flag = 0;
        }

        if (!$(".identity_img_list1").val()) {
            err = '请上传手持身份证照';
            flag = 0;
        }

        if (flag) {
            $("#auth-form").submit();
        } else {
            mui.toast(err);
        }
    });
    function readURL(input, name) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
//                $('.' + name).attr('src', e.target.result);
            };
            reader.readAsDataURL(input.files[0]);
            var formData = new FormData();
            var img_file = input;
            var fileobj = img_file.files[0];
            formData.append("file", fileobj);
            $.showLoading('正在上传');
            $.ajax({
                url: "{:url('ajax/upload')}",
                type: "POST",
                data: formData,
                /**
                 *必须false才会自动加上正确的Content-Type
                 */
                contentType: false,
                /**
                 * 必须false才会避开jQuery对 formdata 的默认处理
                 * XMLHttpRequest会对 formdata 进行正确的处理
                 */
                processData: false,
                success: function (data)
                {
                    $.hideLoading();
                    $.toast(data.msg);
                    $('.' + name).val(data.data.url);
                    $('.'+name).prevAll('.smrz-nav2-ps').css("color","transparent");
                    $('.' + name).parent('li').addClass('img-bg');
                    $('.' + name).parent('li').css("background-image", "url(__OSSCDN__" + data.data.url + ")");
                    isSubmit();
//                    $.post("{:url('My/setuserinfo')}", {avatar: data.data.url}, function (res) {
//                        if (res.code == '0') {
//                            mui.toast(res.msg);
//                        }
//                    }, 'json');
                },
//                error: function () {
//                    alert("上传失败！");
//                }
            });
        }
    }
</script>
{/block}